package com.ycz.algorithm.utils.stack;

import java.util.Stack;

/**
 * @Description
 * @ClassName StackUtil
 * @Author yanchengzhi
 * @date 2024.11.20 23:21
 */
public class StackUtil {

    public static void main(String[] args) {
        // 初始化栈
        Stack<Integer> stack = new Stack<>();
        // 入栈
        stack.push(1); // 最先入栈，成为栈底
        stack.push(3);
        stack.push(2);
        stack.push(5);
        stack.push(4); // 最后入栈，成为栈顶
        System.out.println("栈深度：" + stack.size());
        for (int i : stack) {
            System.out.print(i + "\t");
        }
        System.out.println();
        System.out.println("栈顶元素：" + stack.peek());
        // 出栈
        int num = stack.pop();
        System.out.println("出栈元素是：" + num);
        for (int i : stack) {
            System.out.print(i + "\t");
        }
        System.out.println();
        System.out.println("栈深度：" + stack.size());
        System.out.println("是否为空栈：" + stack.isEmpty());
    }


}
